package com.greenant.store.bean;

import java.io.Serializable;
import java.text.DecimalFormat;

import org.json.JSONException;
import org.json.JSONObject;

public class OrderItem implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = -7336098659174847716L;
	private double quantity;// 用户的购买总数量
	private double weight;// 物品的实际称重量
	private double cost;// 总花费
	private String goodsId;// 商品ID
	private String picUrl;// 商品图片
	private String name;// 商品名称
	private double price;// 商品单价
	private String unit;// 商品单位，单位斤等
	private String weighUnit;// 秤量单位：个等
	private boolean weighAble;// 是否可秤量
	
	
	
	public static final String KEY_QUANTITY="quantity";
	public static final String KEY_COST="cost";
	public static final String KEY_GOODSID="goodsId";
	public static final String KEY_PICURL="picUrl";
	public static final String KEY_NAME="name";
	
	public static final String KEY_PRICE="price";
	public static final String KEY_UNIT="unit";
	public static final String KEY_WEIGHUNIT="weighunit";
	public static final String KEY_WEIGHABLE="weighable";
	public static final String KEY_weight="weight";
	
	public double getPrice() {
	    DecimalFormat df = new DecimalFormat("#########.##");
        return Double.parseDouble(df.format(price));
	}

	public void setPrice(double price) {
		this.price = price;
	}

	public boolean isWeighAble() {
		return weighAble;
	}

	public void setWeighAble(boolean weighAble) {
		this.weighAble = weighAble;
	}

	public String getUnit() {
		return unit;
	}

	public void setUnit(String unit) {
		this.unit = unit;
	}

	public String getWeighUnit() {
		return weighUnit;
	}

	public void setWeighUnit(String weighUnit) {
		this.weighUnit = weighUnit;
	}

	public double getQuantity() {
		return quantity;
	}

	public void setQuantity(double quantity) {
		this.quantity = quantity;
	}

	public double getCost() {
		return cost;
	}

	public void setCost(double cost) {
		this.cost = cost;
	}

	public String getGoodsId() {
		return goodsId;
	}

	public void setGoodsId(String goodsId) {
		this.goodsId = goodsId;
	}

	public String getPicUrl() {
		return picUrl;
	}

	public void setPicUrl(String picUrl) {
		this.picUrl = picUrl;
	}
	
	public JSONObject convertToJson(){
		JSONObject jObject=new JSONObject();
		try {
			jObject.put(KEY_QUANTITY, quantity);
			jObject.put(KEY_COST, cost);
			jObject.put(KEY_GOODSID, goodsId);
			jObject.put(KEY_PICURL, picUrl);
			jObject.put(KEY_NAME, name);
			
			jObject.put(KEY_PRICE, price);
			jObject.put(KEY_UNIT, unit);
			jObject.put(KEY_WEIGHUNIT, weighUnit);
			jObject.put(KEY_WEIGHABLE, weighAble);
			jObject.put(KEY_weight, 0);//创建订单时称重量为0
			
			
		} catch (JSONException e) {
			e.printStackTrace();
		}
		
		return jObject;
	}
	
	public JSONObject getNowJson(){
		JSONObject jObject=new JSONObject();
		try {
			jObject.put(KEY_QUANTITY, quantity);
			jObject.put(KEY_COST, cost);
			jObject.put(KEY_GOODSID, goodsId);
			jObject.put(KEY_PICURL, picUrl);
			jObject.put(KEY_NAME, name);
			
			jObject.put(KEY_PRICE, price);
			jObject.put(KEY_UNIT, unit);
			jObject.put(KEY_WEIGHUNIT, weighUnit);
			jObject.put(KEY_WEIGHABLE, weighAble);
			jObject.put(KEY_weight, weight);//创建订单时称重量为0
			
			
		} catch (JSONException e) {
			e.printStackTrace();
		}
		
		return jObject;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

    public double getWeight()
    {
        return weight;
    }

    public void setWeight(double weight)
    {
        this.weight = weight;
    }
}
